﻿using FDStudio.Core.Entities.Enums;
using FDStudio.Core.Repositories;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace FDStudio.Core.Config
{
    /*
     CreatedOn: 2018-03-08
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// 上下文操作类型存储
    /// </summary>
    public class RepositoryContextContainer : IDictionary<Type, DatabaseOperType>
    {
        private IDictionary<Type, DatabaseOperType> _data;

        public RepositoryContextContainer()
        {
            _data = new Dictionary<Type, DatabaseOperType>();
        }

        public DatabaseOperType this[Type key] { get => _data[key]; set => _data[key] = value; }

        public ICollection<Type> Keys => _data.Keys;

        public ICollection<DatabaseOperType> Values => _data.Values;

        public int Count => _data.Count;

        public bool IsReadOnly => false;

        public void Add(Type key, DatabaseOperType value)
        {
            if (_data.ContainsKey(key))
            {
                _data[key] = value;
            }
            else
            {
                _data.Add(key, value);
            }
        }

        public void Add(KeyValuePair<Type, DatabaseOperType> item)
        {
            if (_data.ContainsKey(item.Key))
            {
                _data[item.Key] = item.Value;
            }
            else
            {
                _data.Add(item);
            }
        }

        public void Clear()
        {
            _data.Clear();
        }

        public bool Contains(KeyValuePair<Type, DatabaseOperType> item)
        {
            return _data.Contains(item);
        }

        public bool ContainsKey(Type key)
        {
            return _data.ContainsKey(key);
        }

        public void CopyTo(KeyValuePair<Type, DatabaseOperType>[] array, int arrayIndex)
        {
            _data.CopyTo(array, arrayIndex);
        }

        public IEnumerator<KeyValuePair<Type, DatabaseOperType>> GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        public bool Remove(Type key)
        {
            return _data.Remove(key);
        }

        public bool Remove(KeyValuePair<Type, DatabaseOperType> item)
        {
            return _data.Remove(item);
        }

        public bool TryGetValue(Type key, out DatabaseOperType value)
        {
            return _data.TryGetValue(key, out value);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _data.GetEnumerator();
        }
    }
}
